import 'package:flutter/material.dart';

void main() {
  runApp(const _DefaultTabControllerScrollTest());
}

class _DefaultTabControllerScrollTest extends StatelessWidget {
  const _DefaultTabControllerScrollTest({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Title of Application',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: const DefaultTabControllerScroll(),
    );
  }
}

class DefaultTabControllerScroll extends StatelessWidget {
  const DefaultTabControllerScroll({super.key});

  @override
  Widget build(BuildContext context) {
    EdgeInsetsDirectional a;
    return DefaultTabController(
        length: 6,
        child: Scaffold(
          appBar: AppBar(
            bottom: createTabBar(),
            title: const Text('Flutter TabBar Example'),
          ),
          body: const TabBarView(
            children: [
              Center(child: Text("Car")),
              Center(child: Text("Transit")),
              Center(child: Text("Bike")),
              Center(child: Text("Boat")),
              Center(child: Text("Railway")),
              Center(child: Text("Bus"))
            ],
          ),
        ));
  }

  TabBar createTabBar() {
    return const TabBar(
      tabs: [
        Row(children: [
          Icon(Icons.directions_car),
          SizedBox(width: 5),
          Text("Car")
        ]),
        Row(children: [
          Icon(Icons.directions_transit),
          SizedBox(width: 5),
          Text("Transit")
        ]),
        Row(children: [
          Icon(Icons.directions_bike),
          SizedBox(width: 5),
          Text("Bike")
        ]),
        Row(children: [
          Icon(Icons.directions_boat),
          SizedBox(width: 5),
          Text("Boat")
        ]),
        Row(children: [
          Icon(Icons.directions_railway),
          SizedBox(width: 5),
          Text("Railway")
        ]),
        Row(children: [
          Icon(Icons.directions_bus),
          SizedBox(width: 5),
          Text("Bus")
        ]),
      ],
      isScrollable: true,
      //indicatorColor属性使您可以指定当前选定选项卡下线的颜色。如果指定了indicator属性，则将忽略此属性
      indicatorColor: Color(0xffE74C3C),

      //indicatorWeight属性用于设置当前选定选项卡下线的粗细。它的值大于0，默认值为2。如果指定了indicator属性，则将忽略此属性
      indicatorWeight: 2,
      indicatorPadding: EdgeInsets.only(right: 10),
    );
  }
}
